<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .router-link-active{
      color: red;
    }
  </style>
</head>
<body>
  <div id="app">
    <router-link custom  v-slot="{ navigate, href, route }" to="/home">
      <button>
        <a :href="href">首页</a>
      </button>
    </router-link>
    <router-link to="/news" active-class="current">新闻页</router-link>
    <router-link replace to="/about">关于我们页</router-link>
    <!-- 视图上 定义 router-view组件 是路由出口 router-view定义在哪里路由组件就在哪里渲染 -->
    <router-view></router-view>
  </div>
  <script src="./vue.global.js"></script>
  <script src="./vue-router.global.js"></script>
  <script>
    const { createApp } = Vue;
    const app = createApp();
    // 1准备路由组件 config
    const HomePage = {
      template: `
        <div>
          <h2>首页</h2>
        </div>
      `
    }
    const NewsPage = {
      template: `
        <div>
          <h2>新闻页</h2>
        </div>
      `
    }
    const AboutPage = {
      template: `
        <div>
          <h2>关于我们页</h2>
        </div>
      `
    }
    // 2创建路由实例
    const routes = [
      {
        path: '/home',
        component: HomePage
      },
      {
        path: '/news',
        component: NewsPage
      },
      {
        path: '/about',
        component: AboutPage
      }
    ]
    const router = VueRouter.createRouter({
      // 创建hash模式的 路由
      history: VueRouter.createWebHashHistory(),
      routes
    })
    // 3 将路由实例挂载  app应用实例上
    app.use(router);
    app.mount('#app')
  </script>
</body>
</html>